<template>
  <div class="login-wrapper">
    <van-checkbox v-model="checked">复选框</van-checkbox>
    <div class="login-content">
      <el-form label-width="100px" :model="formData">
        <el-form-item label="账号" prop="username">
          <el-input v-model="formData.username"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="formData.password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">提交</el-button>
        </el-form-item>
      </el-form>
      <div style="margin-bottom: 2000px"></div>
      <hr />
      <van-image width="100" lazy-load height="100" src="https://img01.yzcdn.cn/vant/cat.jpeg" />
    </div>
  </div>
</template>

<script>
import Vue from 'vue'
import { Lazyload } from 'vant'

Vue.use(Lazyload)
import axios from 'axios'
import { mapMutations } from 'vuex'
export default {
  data() {
    return {
      checked: false,
      formData: {
        username: '',
        password: '',
      },
    }
  },
  methods: {
    ...mapMutations(['SET_LOGIN_TOKEN']),
    async onSubmit() {
      const result = await axios.post('/api/login', this.formData)
      console.log('result:', result)
      this.SET_LOGIN_TOKEN(result.data.data.token)
      this.$router.push('/layout/echarts')

      console.log(this.formData, 'formData')
    },
  },
}
</script>
<style lang="scss" scoped>
.login-wrapper {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
.login-content {
  width: 60%;
  height: 60%;
}
</style>
